
package com.ifcar.app.model;

import com.ifcar.app.util.HttpUtils;
import com.ifcar.app.util.ModelUtils;
import com.ifcar.app.util.NeteaseHttpClient;

import org.json.JSONObject;

import android.content.Context;
import android.text.TextUtils;

import java.util.Map;

public class LatestComment {
    public static final String URL_LATESTCOMMENT = "http://comment.api.163.com/api/json/post/list/new/normal/%s/%s/desc/%d/%d/%d/%d/%d";

    public static final String PARAM_DOCURL = "docUrl";// 原文地址

    public static final String PARAM_CODE = "code";// 请求结果
    
    public static final String PARAM_NEWPOSTS = "newPosts";

    public static final String PARAM_PRCOUNT = "prcount";

    public static final String PARAM_PTCOUNT = "ptcount";
    
    public static final String SUCCESS = "1";// 请求结果成功

    public static Map<String, Object> getLatestComment(Context context, String boardid,
            String docid, int start, int size, int hide, int hideStart, int hideEnd) {
        Map<String, Object> result = null;

        String url = String.format(URL_LATESTCOMMENT, boardid, docid, start, size, hide, hideStart,
                hideEnd);
        String str = HttpUtils.getResponseFromGetUrl(url, 30000, context);

        if (!TextUtils.isEmpty(str)) {
            try {
                JSONObject json = new JSONObject(str);
                result = ModelUtils.json2Map(json);
            } catch (Exception e) {
                e.printStackTrace();
                result = null;
                NeteaseHttpClient.removeCache(context, url);
            }
        }

        return result;
    }
}
